#include<bits/stdc++.h>
using namespace std;
namespace IO{
    const int BUF=1<<21;
    char buff[BUF],*p1=buff,*p2=buff;
    #define gc() (p1==p2&&(p2=((p1=buff)+fread(buff,1,BUF,stdin)),p1==p2)?EOF:*p1++)
    template<typename T>inline void read(T &x){
        char ch=gc();x=0;int f=1;
        while(!isdigit(ch)){if(ch=='-')f=-1;ch=gc();}
        while(isdigit(ch)) x=(x<<1)+(x<<3)+(ch^48),ch=gc();
        x*=f;
    }
    char obuf[BUF],*p3=obuf;
    inline void pc(char ch){
        if(p3-obuf<BUF) *p3++=ch;
        else fwrite(obuf,p3-obuf,1,stdout),p3=obuf,*p3++=ch;
    }
    inline void put(const char *s){while(*s) pc(*s),++s;}
    char ch[32],ctop;
    template<typename T>inline void print(T x){
    	if(x<0) x=~x+1,pc('-');
        if(!x) return pc(48);
        while(x) ch[++ctop]=x%10^48,x/=10;
        while(ctop) pc(ch[ctop--]);
    }
    inline void flush(){fwrite(obuf,p3-obuf,1,stdout);p3=obuf;}
}
using namespace IO;
const int N=1e6+5,inf=2e9+5;
int n,C,cnt,c[N],idx,c2[N],idx2;
vector<int> a[N],T[N];
long long b[N],k[N],sum[N],ans=1e18;
int main(){
	freopen("list.in","r",stdin);
	freopen("list.out","w",stdout);
	read(n);
	c[1]=1,c[idx=2]=inf;
	c2[idx2=1]=inf;
	for(int i=1;i<=n;++i){
		int len;read(len);
		a[i].resize(len);
		for(int j=0;j<len;++j){
			read(a[i][j]),c2[++idx2]=a[i][j];
			if(j) c[++idx]=a[i][j]-a[i][j-1]+1;
		}
	}
	read(C);
	for(int i=1;i<=n;++i) read(b[i]),b[i]*=i;
	sort(c+1,c+idx+1);
	idx=unique(c+1,c+idx+1)-c-1;
	sort(c2+1,c2+idx2+1);
	idx2=unique(c2+1,c2+idx2+1)-c2-1;
	for(int i=1;i<=n;++i){
		T[lower_bound(c2+1,c2+idx2+1,a[i][0])-c2].emplace_back(idx);
		for(int j=0,len;j<a[i].size();++j){
			if(j+1<a[i].size()){
				len=lower_bound(c+1,c+idx+1,a[i][j+1]-a[i][j]+1)-c;
				T[lower_bound(c2+1,c2+idx2+1,a[i][j+1])-c2].emplace_back(len);
			}else len=idx;
			k[1]+=C,k[len]-=C;
			sum[len]+=1ll*C*(c[len]-1);
		}
	}
	for(int i=1;i<=idx2;++i)if(!T[i].empty()){
		sort(T[i].begin(),T[i].end());
		sum[1]+=b[T[i].size()],sum[T[i][0]]-=b[T[i].size()];
		for(int j=0;j<T[i].size();++j){
			sum[T[i][j]]+=b[T[i].size()-j-1];
			if(j+1<T[i].size()) sum[T[i][j+1]]-=b[T[i].size()-j-1];
		}
	}
	vector<int> vec;
	for(int i=1;i<idx;++i){
		k[i]+=k[i-1],sum[i]+=sum[i-1];
		long long now=k[i]*c[i]+sum[i];
		if(now<ans) vec.clear(),vec.push_back(c[i]),ans=now;
		else if(ans==now) vec.push_back(c[i]);
	}
	print(ans),pc(' '),print(vec.size()),pc('\n');
	for(int i:vec) print(i),pc(' ');
	flush();
	return 0;
}


